<input type="text" id="message">
<button id="sendButton">发送</button>

<script>
    let websocket = new WebSocket("ws://127.0.0.1:8080/test");

    websocket.onopen = function() {
        console.log("open!");
    }

    websocket.onclose = function() {
        console.log("close!");
    }

    websocket.onerror = function() {
        console.log("error!");
    }

    websocket.onmessage = function(e) {
        console.log("recv: " + e.data);
    }

    let messageInput = document.querySelector("#message");
    let sendButton = document.querySelector("#sendButton");
    sendButton.onclick = function() {
        console.log("send: " + messageInput.value);
        websocket.send(messageInput.value);
    }
</script>